<?php

abstract class H_Controller_Admin_Action extends H_Rest_Controller
{
    protected $_user_access = null;
    public function init()
    {
        parent::init();
        $this->startLayoutForAdmin();       
        $this->initCss();
        $this->initJs();
        $authStorage = Zend_Auth::getInstance()->getStorage();
	$this->_user_access = $authStorage->read();
        $this->initAuth();
    }
    private function startLayoutForAdmin(){
        $layout = Zend_Layout::getMvcInstance();
        $layout->setLayoutPath(BASE_PATH."templates/admin/");
    }
    private function initCss(){
        $css = array(
            'libjs/ext-4/resources/css/ext-all.css',
            'libjs/ext-4/icons/silk.css',
//            'libjs/ext-3/resources/css/ext-all.css',
//            'libjs/ext-3/ux/css/ux-all.css',
//            'libjs/ext-3/icons/silk.css',
            'templates/admin/css/reset.css',
            'templates/admin/css/main.css',
            'templates/admin/css/slide.css',
            'templates/admin/css/dropdown.css',
            'templates/admin/css/default.advanced.css',                        
            'templates/admin/css/styles.css',
            'templates/admin/css/chantable.css'
        );
        foreach($css as $cssItem){
           $this->view->headLink()->appendStylesheet(BASE_URL.$cssItem);
        }        
    }
    private function initJs(){        
        $js = array(
            //'libjs/ext-3/adapter/ext/ext-base-debug.js',
            //'libjs/ext-3/ext-all-debug.js',
            //'libjs/ext-3/ux/ux-all-debug.js',
            'libjs/ext-4/bootstrap.js',            
            'templates/admin/js/jquery-1.4.4.js',
            'templates/admin/js/jquery.form.js',          
            'templates/admin/js/jquery.validate.js',
            'templates/admin/js/slide.js',
            'templates/admin/js/changepass_form.js',
            'libjs/ckeditor/ckeditor.js',
            'libjs/ckeditor/lang/_languages.js',
            //'libjs/ckfinder/ckfinder.js',
            //'libjs/jquery-impromptu.3.1.min.js',
            'admin/initjavascript',            
            'libjs/cms.js'
            
        );
        
        foreach($js as $jsItem){
           $this->view->headScript()->appendFile(BASE_URL.$jsItem,'text/javascript',array('charset'=>'UTF-8'));
        }
    }
    private function initAuth()
    {
            $module = $this->_request->getModuleName();
            $session = new Zend_Session_Namespace("currentModule");
            $session->currentModule = $module;
            if (!Zend_Auth::getInstance()->hasIdentity())
            {
                    $this->_redirect("admin/auth/login");
            }
    }
    public function postDispatch(){
        parent::postDispatch();
    	$this->view->current_user = $this->_user_access;
    }
    public function  preDispatch() {
        parent::preDispatch();        
    }

    protected function desibleLayout(){
        $this->_helper->layout()->disablelayout();
        $this->_helper->viewRenderer->setNoRender(true);
    }
}
?>
